#ifndef __RANK_H__
#define __RANK_H__
#include "membackend/accurateBank.h"
#include "membackend/accurateIRankTiming.h"
#include <vector>
#include <cstdint>
#include <iostream>
#include <deque>


class Rank : public IRankTiming
{
private:
    AddressMappingConfig *amp;
    std::vector<std::vector<Bank>> m_bankVector;
    std::deque<uint64_t> FAW;
    
    uint64_t m_numBanks;
    uint64_t m_numBankGroups;

    bool is_ACT;
    uint64_t last_act_time;
    uint64_t last_pre_time;
    uint64_t last_rw_time;

    uint64_t last_bank_id; // 最近访问的bank ID
    uint64_t last_bankGroup_id; // 最近访问的bankGroup ID

public:
    Rank();
    Rank(uint64_t numBanks, uint64_t numBankGroups);
    int Init(AddressMappingConfig *amp);
    Bank& getBank(uint64_t bank_group_id, uint64_t bank_id);
    



    uint64_t getLastBankId() const override { return last_bank_id; }
    uint64_t getLastBankGroupId() const override { return last_bankGroup_id; }
    uint64_t getLastACTTime() const override { return last_act_time; }
    uint64_t getLastPRETime() const override { return last_pre_time; }
    uint64_t getLastRWTime() const override { return last_rw_time; }
    uint64_t getIsACT() const override { return is_ACT; }

    void setLastBankId(uint64_t bank_id) override { last_bank_id = bank_id; }
    void setLastBankGroupId(uint64_t bankGroup_id) override { last_bankGroup_id = bankGroup_id; }
    void setLastACTTime(uint64_t time) override { last_act_time = time; }
    void setLastPRETime(uint64_t time) override { last_pre_time = time; }
    void setLastRWTime(uint64_t time) override { last_rw_time = time; }
    void setIsACT(bool is_ACT) override { this->is_ACT = is_ACT; }

    // 处理激活命令的函数
    uint64_t getRankFAWConstrain(uint64_t bankgroup_id, uint64_t bank_id, uint64_t time) override;

    // 处理读写命令的函数
    uint64_t getRankRRDConstrain(uint64_t bankgroup_id, uint64_t bank_id, uint64_t time) override;


};

#endif